package com.foreknow.elm.controller;

import com.foreknow.elm.service.DeliveryService;
import com.foreknow.elm.service.impl.DeliveryServiceImpl;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 啊滨
 * @date 2023/2/14 14:30
 */
public class DeliveryController {
    public Object listDeliveryAddressByUserId(HttpServletRequest request){
        String userId = request.getParameter("userId");
        DeliveryService service=new DeliveryServiceImpl();
        return service.listDeliveryAddressByUserId(userId);
    }

    public Object getDeliveryAddressById(HttpServletRequest request){
        int daId = Integer.parseInt(request.getParameter("daId"));
        DeliveryService service=new DeliveryServiceImpl();
        return service.getDeliveryAddressById(daId);
    }

    public Object saveDeliveryAddress(HttpServletRequest request){
        int isRight=0;
        String contactName = request.getParameter("contactName");
        int contactSex = Integer.parseInt(request.getParameter("contactSex"));
        String contactTel = request.getParameter("contactTel");
        String address = request.getParameter("address");
        String userId = request.getParameter("userId");
        DeliveryService service=new DeliveryServiceImpl();
        isRight = service.saveDeliveryAddress(contactName, contactSex, contactTel, address, userId);
        return isRight;
    }
    public Object updateDeliveryAddress(HttpServletRequest request){
        int isRight=0;
        String contactName = request.getParameter("contactName");
        int contactSex = Integer.parseInt(request.getParameter("contactSex"));
        String contactTel = request.getParameter("contactTel");
        String address = request.getParameter("address");
        String userId = request.getParameter("userId");
        int daId =Integer.parseInt(request.getParameter("daId")) ;
        DeliveryService service=new DeliveryServiceImpl();
        isRight = service.updateDeliveryAddress(daId,contactName, contactSex, contactTel, address, userId);
        return isRight;
    }
    public Object removeDeliveryAddress(HttpServletRequest request){
        int isRight=0;
        int daId = Integer.parseInt(request.getParameter("daId"));
        DeliveryService service=new DeliveryServiceImpl();
        isRight=service.removeDeliveryAddress(daId);
        return isRight;
    }
}
